home *** CD-ROM | disk | FTP | other *** search
- /*
- ┌────────────────────────────────────────────────────────────────────────────┐
- │ Title : Cprint.c │
- │ Purpose : Allow multiple printing of programs, with wildcards and various │
- │ │
- │ formatting options. │
- │ -d specifies double strike printing │
- │ -e specifies emphasized printing │
- │ -t specifies title of document + time and date │
- │ -w specifies wide (compressed) listing │
- │ -n specifies to number the lines │
- │ -c specifies output to console │
- │ -mn specifies multiple copies where n is 1..num of copies │
- │ │
- │Written using Lattice C v 2.15e, translated to Microsoft C v3.0 on 1/15/86 │
- │ │
- │ Written by Jack Zucker - 75766,1336 301-794-5950 │ │
- └────────────────────────────────────────────────────────────────────────────┘
- */
- #include <stdio.h> /* standard header file */
- #include <dos.h> /* register definitions */
- #include <time.h> /* Ms C time struct */
- #include <stdlib.h> /* standard functions */
- #include "jzdirect.h" /* defines my dir struct */
- #include "jzfndfst.c" /* get first matching file */
- #include "jzfndnxt.c" /* get next matching file */
-
- #define FF 0x0c /* form feed */
- #define PGLEN 60 /* length of a page */
- #define PROUT 0x17 /* bios printer function */
- #define COMPRS 0x0f /* epson compressed code */
- #define BUFSIZE 1024 /* text buffer size */
- #define HEADING Listing of
- #define ESC 0x1b /* hex esc code */
- #define TITLE1 "Listing of "
- #define TITLE2 " on "
- #define TITLE3 " PAGE: "
- #define DBL 71 /* epson double strike code */
- #define EMPH 69 /* epson emphasized code */
-
-
- int lineno,colno,lineslft,width = 80,pagenum;
-
- struct tm *wtime;
- char *wasctime;
-
- TDIR wdir;
-
- /* switches */
- int NUMBER = 0,WIDE = 0,TITLE = 0,CONSOLE = 0;
- int DOUBLE = 0,EMPHASIZ = 0,MULTIPLE = 1;
-
- char mask[35]; /* global variables */
- char wpath[35],wtemp[50];
- union REGS inregs,outregs; /* register struct */
-
-
- main (argc,argv)
- int argc;
- char *argv[];
-
- {
- char buf[BUFSIZE],*s,*ch;
- long wtics;
- int c,n,w;
- FILE *fd;
- int werr;
-
-
- n = BUFSIZE; /* read buf size */
- strcpy(mask,*++argv); /* mask = filespec */
-
- for (w = strlen(mask) ; w >= 0 ; w -- )
- if (mask[w] == '\\' || mask[w] == ':') break;
-
- if (w >= 0) {
- strcpy(wpath,mask);
- wpath[++w] = '\0';
- }
- else *wpath = '\0';
-
- time(&wtics);
- wtime = gmtime(&wtics);
- wasctime = asctime(wtime);
- w = strlen(wasctime);
- wasctime[--w] = '\0';
- while (--argc > 0 && (*++argv)[0] == '-') /* parse through options */
- for (s = argv[0]+1; *s ; s ++)
- switch(*s) {
- case 'w' : /* wide printing */
- WIDE = 1;
- break;
- case 'n' : /* number lines */
- NUMBER = 1;
- break;
- case 't' :
- TITLE = 1; /* title and heading */
- break;
- case 'd' :
- DOUBLE = 1; /* double strike */
- break;
- case 'e' :
- EMPHASIZ = 1; /* emphasized */
- break;
- case 'm' :
- MULTIPLE = (*(++s) - 48); /* multiple copies */
- break;
- case 'c' :
- CONSOLE = 1; /* output to console (stdout) */
- break;
- default: /* invalid option */
- printf("\nIllegal option %c",*s);
- argc = 0;
- break;
- }
-
- /* help or bad options */
- if (argc != 1 || (mask[0] == '?' && strlen(mask) == 1)) {
- printf("\n\nCprint v2.0 by Jaz (Jack A. Zucker) 75766,1336");
- printf("\nRevised for Microsoft C v3.0 1/14/86");
- printf("\nusage CPRINT filespec (including wildcards) [-nwdetlimc]\n");
- printf("\n\t-d specifies double strike printing");
- printf("\n\t-e specifies emphasized printing");
- printf("\n\t-t specifies title of document + time and date");
- printf("\n\t-w specifies wide (compressed) listing");
- printf("\n\t-n specifies to number the lines");
- printf("\n\t-c specifies output to console");
- printf("\n\t-mn specifies multiple copies where n is 1..num of copies\n");
- exit();
- }
-
- while (MULTIPLE -- ) { /* allow for mult copies */
- werr = jzfndfst(mask,32,&wdir); /* get first matching file */
- if (!werr)
- do { /* until no more files */
- strcpy(wtemp,wpath);
- strcat(wtemp,wdir.dirname);
- if (!( fd = fopen(wtemp,"r"))) { /* open for read only */
- /* bad file or it ain't there */
- printf("\nCan't find %s",wdir.dirname);
- exit();
- }
- glbinit(); /* initialize various vars */
- getflags(); /* look at switch settings */
- formfeed (); /* page feed */
-
- /* while not eof do begin */
- while ( (ch = fgets(buf,n,fd)) ) {
- if (linepr(buf)) continue; /* main print routine */
- if (! lineslft) formfeed (); /* formfeed if appropriate */
- }
-
- putlpr('\n'); /* flush print buffer */
- fclose(fd); /* close input file */
- werr = jzfndnxt(&wdir); /* get next matching file */
- } while (! werr);
- else {
- printf("No match for %s",mask);
- exit();
- }
- }
- }
-
-
- glbinit() /* init page and line numbers */
- {
- lineno = 0;
- pagenum = 0;
- }
-
-
- linepr (string)
- char *string;
- {
- char c;
- int ffflag = 0;
-
- while ( c = *string ++) {
- if ( ( ! colno ) && NUMBER ) {
- printnum(++ lineno);
- colno += 6;
- }
- switch (c) {
-
- case FF :
- ffflag = 1;
- break;
-
- case '\n' :
- putlpr('\n');
- putlpr('\r');
- colno = 0;
- if (! (lineslft --)) formfeed ();
- break;
-
- case '\t' :
- do {
- putlpr (' ');
- colno ++;
- if (! ( ( (NUMBER) ? width - 8 : width) - colno ) ) {
- putlpr('\n');
- putlpr('\r');
- if (! (lineslft --)) formfeed ();
- colno = 0;
- }
- } while ( colno % 8 );
- break;
-
- default:
- putlpr (c);
- colno ++;
- if (! ( ( (NUMBER) ? width - 8 : width) - colno ) ) {
- putlpr('\n');
- putlpr('\r');
- if (! (lineslft --)) formfeed ();
- colno = 0;
- }
- } /* switch */
- }
- if (ffflag) formfeed ();
- return ffflag;
- }
-
-
- putlpr (c)
- char c;
- {
- if (CONSOLE) printf("%c",c);
- else {
- inregs.h.ah = 0;
- inregs.h.al = c;
- int86(PROUT,&inregs,&outregs);
- }
- }
-
-
- formfeed ()
- {
- if (FF) putlpr(FF);
- else while (lineslft--) putlpr('\n');
- if (TITLE) heading();
- lineslft = PGLEN - 4;
- colno = 0;
- }
-
-
- static int EMPHON [] = { '\n',ESC,'E',ESC,'G' };
- static int EMPHOFF[] = { '\n','\n','\n','\r',ESC,'F',ESC,'H' };
-
- heading()
- {
- char strnum[5];
- int i;
- itoa(++pagenum,strnum,10);
- putbuflpr(EMPHON,5);
- strputlpr(TITLE1);
- strputlpr(wdir.dirname);
- strputlpr(TITLE2);
- strputlpr(wasctime);
- strputlpr(TITLE3);
- strputlpr(strnum);
- putbuflpr(EMPHOFF,8);
- getflags();
-
- }
-
-
- getflags()
- {
-
- if (WIDE) {
- putlpr(COMPRS);
- width = 132;
- }
-
- if (DOUBLE) {
- putlpr(ESC);
- putlpr(DBL);
- }
-
- if (EMPHASIZ) {
- putlpr(ESC);
- putlpr(EMPH);
- }
-
- }
-
-
- putbuflpr(buf,len)
- int *buf,len;
- {
- int i;
- for ( i = 0 ; i < len ; i ++ ) putlpr(buf[i]);
- }
-
-
- strputlpr(s)
- char *s;
- {
- while (*s) putlpr(*s++);
- }
-
-
- printnum(n)
- int n;
- {
- int i,j;
- char s[8];
- i = 0;
- strcpy(s," ");
- do {
- s [i++] = n % 10 + '0';
- j = i;
- } while ((n /= 10) > 0);
- s [i] = '\0';
- for ( i = 7 ; i > - 1 ; i --) putlpr (s [i]);
- putlpr('>');
- putlpr(' ');
- }